﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using CoolCode.Linq.Expressions;

namespace CoolCode.Linq
{
    public static class IQueryableExtensions
    {
        #region  分页

        /// <summary>
        /// 分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static IQueryable<T> Pagination<T>(this IQueryable<T> source, int pageIndex, int pageSize)
        {
            return (IQueryable<T>)source.Skip((pageIndex - 1) * pageSize).Take(pageSize);
        }

        public static IQueryable<T> Pagination<T>(this IQueryable<T> source, Func<T, bool> predicate, int pageIndex, int pageSize)
        {
            return (IQueryable<T>)source.Where(predicate).Skip((pageIndex - 1) * pageSize).Take(pageSize);
        }

        #endregion
    }
}
